package com.wu.controller.system;

import com.wu.base.ApiResponse;
import com.wu.base.PageInfoData;
import com.wu.controller.BaseController;
import com.wu.pojo.reqeust.CommonIdRequest;
import com.wu.pojo.reqeust.CommonIdStatusRequest;
import com.wu.pojo.reqeust.sys.DepartmentEditRequest;
import com.wu.pojo.reqeust.sys.DepartmentListRequest;
import com.wu.pojo.reqeust.sys.DepartmentSaveRequest;
import com.wu.pojo.reqeust.sys.DepartmentTreeListRequest;
import com.wu.pojo.response.sys.DepartmentListResponse;
import com.wu.pojo.response.sys.DepartmentTreeUserListResponse;
import com.wu.service.sys.SDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 部门表(SDepartment)表控制层
 *
 * @since 2020-12-29 13:20:26
 */
@Api(tags = {"S部门相关接口"})
@RestController
@RequestMapping("/department")
public class SDepartmentController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SDepartmentService sDepartmentService;

    @ApiOperation(value = "部门树列表")
    @RequiresPermissions("/department/treeList")
    @PostMapping(value = "/treeList")
    public ApiResponse<DepartmentListResponse> treeList(@Validated() @RequestBody DepartmentTreeListRequest request) {
        return sDepartmentService.treeList(request);
    }

    @ApiOperation(value = "列表")
    @RequiresPermissions("/department/list")
    @PostMapping(value = "/list")
    public ApiResponse<PageInfoData<DepartmentListResponse>> list(@Validated() @RequestBody DepartmentListRequest request) {
        return sDepartmentService.list(request);
    }

    @ApiOperation(value = "下拉选择列表")
    @RequiresPermissions("/department/optionList")
    @PostMapping(value = "/optionList")
    public ApiResponse<DepartmentListResponse> optionList(@Validated() @RequestBody DepartmentTreeListRequest request) {
        return sDepartmentService.optionList(request);
    }

    @ApiOperation(value = "新增")
    @RequiresPermissions("/department/save")
    @PostMapping(value = "/save")
    public ApiResponse save(@Validated() @RequestBody DepartmentSaveRequest request) {
        return sDepartmentService.save(request);
    }

    @ApiOperation(value = "修改")
    @RequiresPermissions("/department/edit")
    @PostMapping(value = "/edit")
    public ApiResponse edit(@Validated() @RequestBody DepartmentEditRequest request) {
        return sDepartmentService.edit(request);
    }

    @ApiOperation(value = "删除")
    @RequiresPermissions("/department/delete")
    @PostMapping(value = "/delete")
    public ApiResponse delete(@Validated() @RequestBody CommonIdRequest request) {
        return sDepartmentService.delete(request);
    }

    @ApiOperation(value = "停用/启用")
    @RequiresPermissions("/department/onOrOff")
    @PostMapping(value = "/onOrOff")
    public ApiResponse onOrOff(@Validated() @RequestBody CommonIdStatusRequest request) {
        return sDepartmentService.onOrOff(request);
    }

    @ApiOperation(value = "单个查询")
    @RequiresPermissions("/department/getById")
    @PostMapping(value = "/getById")
    public ApiResponse<DepartmentListResponse> getById(@Validated() @RequestBody CommonIdRequest request) {
        return sDepartmentService.getById(request);
    }

    @ApiOperation(value = "部门树列表及部门下人员")
    @RequiresPermissions("/department/treeAndUser")
    @PostMapping(value = "/treeAndUser")
    public ApiResponse<DepartmentTreeUserListResponse> treeAndUser(@Validated() @RequestBody DepartmentTreeListRequest request) {
        return sDepartmentService.treeAndUser(request);
    }



}